package org.example.mall.Service.impl;

import org.example.mall.Mapper.ConsigneeInfoMapper;
import org.example.mall.Pojo.ConsigneeInfo;
import org.example.mall.Service.ConsigneeInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ConsigneeInfoServiceimpl implements ConsigneeInfoService {
    @Autowired
    private ConsigneeInfoMapper cMapper;
    @Override
    public List<ConsigneeInfo> getConsigneeListByUserName(String userName) {
        return cMapper.getConsigneeInfoListByUserName(userName);
    }
    @Override
    public ConsigneeInfo getConsigneeByCId(Integer cId) {
        return cMapper.getConsigneeInfoByCId(cId);
    }
    @Override
    public void createConsignee(String userName, String consigneeName, String consigneePhone, String consigneeAddress) {
        cMapper.createConsigneeInfo(userName, consigneeName, consigneePhone, consigneeAddress, "86");
    }
    @Override
    public void createConsignee(String userName, String consigneeName, String consigneePhone, String consigneeAddress, String areaCode) {
        cMapper.createConsigneeInfo(userName, consigneeName, consigneePhone, consigneeAddress, areaCode);
    }
    @Override
    public void deleteConsignee(Integer cId) {
        cMapper.deleteConsigneeInfo(cId);
    }

    @Override
    public void updateToNoUserNameConsignee(Integer cId) {
        cMapper.UpdateUserNameToNull(cId);
    }
    @Override
    public void updateConsignee(Integer cId, Map<String, String> updateDate) {
        for(String key : updateDate.keySet()) {
            switch (key){
                case "consigneeName":cMapper.updateConsigneeName(cId,updateDate.get(key));break;
                case "consigneePhone":cMapper.updateConsigneeName(cId,updateDate.get(key));break;
                case "consigneeAddress":cMapper.updateConsigneeName(cId,updateDate.get(key));break;
            }
        }
    }
}
